/* GIVE ME SPACE UP TOP */


******************************** PROTECTIONS **********************************
******************************** EARLY PERIOD *********************************

use "[path_to_.dta_file_here.dta]"

******************** variable set up and creation ********************
sort id year

*recoding those handful of states that started as low/mid income then 
*moved to high inc over the course of the study (mostly post-Soviet)
recode lend_grp (1=1) (2=2) (3 4=3) (.=.)
tab lend_grp, gen(g)
rename g1 lowinc_dum
rename g2 lowmidinc_dum 
rename g3 upmid_highinc_dum

*making Beijing conference/attendance indicator for imputation model
tab og_beij, gen(g)
rename g1 pre_beij
rename g2 beij_norep
rename g3 beij_lt10
rename g4 beij_10om

gen igo_log = log(igo_imp)
gen ingo_log = log(ingo_imp)
gen gdppc_2018 = gdp_2018doll/pop_tot
gen log_pop = log(pop_tot)
gen log_gdppc = log(gdppc_2018)

*making early period adopter flag
gen s1 = dvprot_yr
recode s1 (1990/2003 0 = 1) (2004/2015 = 0) 


***/// Centering variables
sum tds_pct_gni if s1==1 & year < 2004, meanonly
gen tds_pct_gnic = tds_pct_gni-r(mean)
sum tds_pct_gnic if s1==1 & year < 2004
drop tds_pct_gni
rename tds_pct_gnic tds_pct_gni

sum urb_pop_pct if s1==1 & year < 2004, meanonly
gen urb_pop_pctc = urb_pop_pct-r(mean)
sum urb_pop_pctc if s1==1 & year < 2004
drop urb_pop_pct
rename urb_pop_pctc urb_pop_pct

sum polity if s1==1 & year < 2004, meanonly
gen polityc = polity-r(mean)
sum polityc if s1==1 & year < 2004
drop polity
rename polityc polity

sum year_from_suff if s1==1 & year < 2004, meanonly
gen year_from_suffc = year_from_suff-r(mean)
sum year_from_suffc if s1==1 & year < 2004
drop year_from_suff
rename year_from_suffc year_from_suff

sum reg_diff_dvprot if s1==1 & year < 2004, meanonly
gen reg_diff_dvprotc = reg_diff_dvprot-r(mean)
sum reg_diff_dvprotc if s1==1 & year < 2004
drop reg_diff_dvprot
rename reg_diff_dvprotc reg_diff_dvprot

sum log_elect if s1==1 & year < 2004, meanonly
gen log_electc = log_elect-r(mean)
sum log_electc if s1==1 & year < 2004
drop log_elect
rename log_electc log_elect

sum femschool_log if s1==1 & year < 2004, meanonly
gen femschool_logc = femschool_log-r(mean)
sum femschool_logc if s1==1 & year < 2004
drop femschool_log
rename femschool_logc femschool_log

sum hr_log if s1==1 & year < 2004, meanonly
gen hr_logc = hr_log-r(mean)
sum hr_logc if s1==1 & year < 2004
drop hr_log
rename hr_logc hr_log

sum wing_log if s1==1 & year < 2004, meanonly
gen wing_logc = wing_log-r(mean)
sum wing_logc if s1==1 & year < 2004
drop wing_log
rename wing_logc wing_log

sum femleg_log if s1==1 & year < 2004, meanonly
gen femleg_logc = femleg_log-r(mean)
sum femleg_logc if s1==1 & year < 2004
drop femleg_log
rename femleg_logc femleg_log

sum log_gdppc if s1==1 & year < 2004, meanonly
gen log_gdppcc = log_gdppc-r(mean)
sum log_gdppcc if s1==1 & year < 2004
drop log_gdppc
rename log_gdppcc log_gdppc

sum tds_pct_gni urb_pop_pct log_elect polity ///
femschool_log year_from_suff femleg_log hr_log ///
wing_log reg_diff_dvprot if s1==1


*generating interactions for use in models and imputation model
gen lowmidXdiff = lowmidinc_dum*reg_diff_dvprot
gen lowmidXwingos = lowmidinc_dum*wing_log
gen lowmidXfemleg = lowmidinc_dum*femleg_log
gen lowmidXcedaw = lowmidinc_dum*non29res_cedaw_rat

gen lowincXdiff = lowinc_dum*reg_diff_dvprot
gen lowincXcedaw = lowinc_dum*non29res_cedaw_rat
gen lowincXwingos = lowinc_dum*wing_log
gen lowincXfemleg = lowinc_dum*femleg_log

gen diffXwingos = reg_diff_dvprot*wing_log
gen cedawXwingos = non29res_cedaw_rat*wing_log


*******/////// Imputation procedure for DVPROT_EP

//** set mi style
mi set flong


//** declare variables for imputation
mi register imputed tds_pct_gni wing_log femleg_log lowincXfemleg lowmidXfemleg ///,
femschool_log wingos lowincXwingos lowmidXwingos femschool_sec_gross igo_log ingo_log ///,
gdppc_2018 gdp_2018doll log_gdppc log_pop gdppc_2010 diffXwingos ///,
cedawXwingos 


***/// Use MICE imputation - DVPROT_EP 

mi impute chained (pmm, knn(6)) tds_pct_gni wing_log femschool_sec_gross ///,
femschool_log lowincXwingos lowmidXwingos wingos igo_log ingo_log ///
femleg_log lowincXfemleg lowmidXfemleg gdp_2018doll log_gdppc log_pop diffXwingos ///,
cedawXwingos gdppc_2018 gdppc_2010 =  ///,
dvprot SSA_dum MENA_dum ASIPAC_dum CCE_dum urb_pop_pct i.lowinc_dum pop_tot ///,
i.lowmidinc_dum left_part log_elect polity prop_rep mix_other dvprot_anyn ///,
year_from_suff hr_log non29res_cedaw_rat ///,
post_beij demo_trans mort_u5 reg_diff_dvprot beij_norep ///,
lowincXcedaw lowmidXcedaw lowincXdiff lowmidXdiff ///,
beij_lt10 beij_10om pop_mil pop_0to14_pct fert_bpw i.id ///,
i.year if exist_flag==1 & year<2004, rseed(15132086) burnin(25) add(100) ///
force aug dots


* set sample
gen sample = 0
replace sample =1 if ///,
SSA_dum !=. & MENA_dum !=. & ASIPAC_dum !=. & CCE_dum !=. & tds_pct_gni !=. & ///,
urb_pop_pct !=. & lowmidinc_dum !=. & lowinc_dum !=. & log_elect !=. & polity ///,
!=. & prop_rep !=. & mix_other !=. & femschool_log !=. & year_from_suff !=. & ///,
femleg_log !=. & hr_log !=. & non29res_cedaw_rat !=. & wing_log !=. & ///, 
reg_diff_dvprot !=. & log_gdppc !=.

*mi stset data and check impute stats
mi stset end if exist_flag==1 & s1==1 & year < 2004, failure(dvprot==1) ///, 
time0(start) id(id) exit(dvprot==1)
mi describe


******************** MODELS ********************

*region only
mi estimate, saving(estfile1, replace) esample(esample2) ufmitest: streg   ///,
SSA_dum MENA_dum ASIPAC_dum CCE_dum if sample==1 & id != 119, dist(exp) vce(cluster id) time

mi estimate, hr
mi estimate, vartable dftable
how_many_imputations

mi test SSA_dum MENA_dum ASIPAC_dum CCE_dum, ufmitest


*base
mi estimate, saving(estfile1, replace) esample(esample42) ufmitest: streg   ///,
SSA_dum MENA_dum ASIPAC_dum CCE_dum tds_pct_gni urb_pop_pct lowmidinc_dum ///,
lowinc_dum log_elect polity prop_rep mix_other femschool_log year_from_suff ///,
femleg_log hr_log non29res_cedaw_rat wing_log reg_diff_dvprot log_gdppc ///,
if id != 119, dist(exp) vce(cluster id) time

mi estimate, hr
mi estimate, vartable dftable
how_many_imputations


mi test SSA_dum MENA_dum ASIPAC_dum CCE_dum, ufmitest

mi test lowmidinc_dum lowinc_dum, ufmitest

mi test prop_rep mix_other, ufmitest



*base + incXcedaw
mi estimate, saving(estfile1, replace) esample(esample1001) ufmitest: streg   ///,
SSA_dum MENA_dum ASIPAC_dum CCE_dum tds_pct_gni urb_pop_pct lowmidinc_dum ///,
lowinc_dum log_elect polity prop_rep mix_other femschool_log year_from_suff log_gdppc ///,
femleg_log hr_log non29res_cedaw_rat lowincXcedaw lowmidXcedaw ///,
reg_diff_dvprot wing_log if id != 119, dist(e) vce(cluster id) time

mi estimate, hr
mi estimate, vartable dftable
how_many_imputations


mi test SSA_dum MENA_dum ASIPAC_dum CCE_dum, ufmitest

mi test lowmidinc_dum lowinc_dum, ufmitest

mi test prop_rep mix_other, ufmitest

mi test lowincXcedaw lowmidXcedaw, ufmitest


*MICE margins 
mimrgns using estfile1, esample(esample1001) at(non29res_cedaw_rat=(0 1) ///,
lowmidinc_dum=(0 1) lowinc_dum=(0 1)) vsquish cmdmargins eform

collin tds_pct_gni urb_pop_pct log_elect polity femschool_log year_from_suff ///,
femleg_log hr_log wing_log reg_diff_dvprot log_gdppc if sample==1 & _st==1


clear


















































































******************************** PROTECTIONS *********************************
******************************** FULL PERIOD *********************************

use "[path_to_.dta_file_here.dta]"

******************** variable set up and creation ********************
sort id year

*recoding those handful of states that started as low/mid income then 
*moved to high inc over the course of the study (mostly post-Soviet)
recode lend_grp (1=1) (2=2) (3 4=3) (.=.)
tab lend_grp, gen(g)
rename g1 lowinc_dum
rename g2 lowmidinc_dum 
rename g3 upmid_highinc_dum

*making Beijing conference/attendance indicator for imputation model
tab og_beij, gen(g)
rename g1 pre_beij
rename g2 beij_norep
rename g3 beij_lt10
rename g4 beij_10om

gen igo_log = log(igo_imp)
gen ingo_log = log(ingo_imp)
gen gdppc_2018 = gdp_2018doll/pop_tot
gen log_pop = log(pop_tot)
gen log_gdppc = log(gdppc_2018)


***/// Centering variables
sum tds_pct_gni, meanonly
gen tds_pct_gnic = tds_pct_gni-r(mean)
sum tds_pct_gnic
drop tds_pct_gni
rename tds_pct_gnic tds_pct_gni

sum ingo_log, meanonly
gen ingo_logc = ingo_log-r(mean)
sum ingo_logc
drop ingo_log
rename ingo_logc ingo_log

sum igo_log, meanonly
gen igo_logc = igo_log-r(mean)
sum igo_logc
drop igo_log
rename igo_logc igo_log

sum urb_pop_pct, meanonly
gen urb_pop_pctc = urb_pop_pct-r(mean)
sum urb_pop_pctc 
drop urb_pop_pct
rename urb_pop_pctc urb_pop_pct

sum polity, meanonly
gen polityc = polity-r(mean)
sum polityc
drop polity
rename polityc polity

sum year_from_suff, meanonly
gen year_from_suffc = year_from_suff-r(mean)
sum year_from_suffc
drop year_from_suff
rename year_from_suffc year_from_suff

sum reg_diff_dvprot, meanonly
gen reg_diff_dvprotc = reg_diff_dvprot-r(mean)
sum reg_diff_dvprotc
drop reg_diff_dvprot
rename reg_diff_dvprotc reg_diff_dvprot

sum log_elect, meanonly
gen log_electc = log_elect-r(mean)
sum log_electc
drop log_elect
rename log_electc log_elect

sum femschool_log, meanonly
gen femschool_logc = femschool_log-r(mean)
sum femschool_logc
drop femschool_log
rename femschool_logc femschool_log

sum hr_log, meanonly
gen hr_logc = hr_log-r(mean)
sum hr_logc
drop hr_log
rename hr_logc hr_log

sum wing_log, meanonly
gen wing_logc = wing_log-r(mean)
sum wing_logc
drop wing_log
rename wing_logc wing_log

sum femleg_log, meanonly
gen femleg_logc = femleg_log-r(mean)
sum femleg_logc
drop femleg_log
rename femleg_logc femleg_log

sum log_gdppc, meanonly
gen log_gdppcc = log_gdppc-r(mean)
sum log_gdppcc
drop log_gdppc
rename log_gdppcc log_gdppc


*generating interactions for use in models and imputation model
gen lowmidXdiff = lowmidinc_dum*reg_diff_dvprot
gen lowmidXwingos = lowmidinc_dum*wing_log
gen lowmidXfemleg = lowmidinc_dum*femleg_log
gen lowmidXcedaw = lowmidinc_dum*non29res_cedaw_rat

gen lowincXwingos = lowinc_dum*wing_log
gen lowincXfemleg = lowinc_dum*femleg_log
gen lowincXdiff = lowinc_dum*reg_diff_dvprot
gen lowincXcedaw = lowinc_dum*non29res_cedaw_rat

gen diffXwingos = reg_diff_dvprot*wing_log
gen cedawXwingos = non29res_cedaw_rat*wing_log


*******/////// Imputation procedure for DVPROT_FP

//** set mi style
mi set flong


//** declare variables for imputation
mi register imputed tds_pct_gni wing_log femleg_log lowincXfemleg lowmidXfemleg  ///,
femschool_log wingos lowincXwingos lowmidXwingos femschool_sec_gross igo_log ingo_log ///,
gdppc_2018 gdp_2018doll log_gdppc log_pop gdppc_2010 diffXwingos ///,
cedawXwingos 


***/// Use ICE imputation DVPROT_FP

mi impute chained (pmm, knn(8)) tds_pct_gni wing_log  ///,
femschool_log lowmidXwingos lowincXwingos wingos igo_log ingo_log ///
femleg_log lowincXfemleg lowmidXfemleg gdp_2018doll log_gdppc log_pop diffXwingos ///,
cedawXwingos gdppc_2018 gdppc_2010 ///,
 = dvprot SSA_dum MENA_dum ASIPAC_dum CCE_dum urb_pop_pct lowinc_dum pop_tot ///,
lowmidinc_dum left_part log_elect polity prop_rep mix_other dvprot_anyn ///,
year_from_suff hr_log non29res_cedaw_rat ///,
post_beij demo_trans mort_u5 reg_diff_dvprot beij_norep ///,
lowincXcedaw lowmidXcedaw lowincXdiff lowmidXdiff ///,
beij_lt10 beij_10om pop_mil pop_0to14_pct fert_bpw i.id ///,
i.year if exist_flag==1, rseed(15132086) ///,
burnin(25) add(100) force aug dots


* set sample
gen sample = 0
replace sample =1 if ///,
SSA_dum !=. & MENA_dum !=. & ASIPAC_dum !=. & CCE_dum !=. & tds_pct_gni !=. & ///,
urb_pop_pct !=. & lowmidinc_dum !=. & lowinc_dum !=. & log_elect !=. & polity ///,
!=. & prop_rep !=. & mix_other !=. & femschool_log !=. & year_from_suff !=. & ///,
femleg_log !=. & hr_log !=. & non29res_cedaw_rat !=. & wing_log !=. & ///, 
reg_diff_dvprot !=. & log_gdppc !=.


*mi stset data and check impute stats
mi stset end if exist_flag==1, failure(dvprot==1) time0(start) id(id) exit(dvprot==1)
mi describe


******************** MODELS ********************


*region only
mi estimate, saving(estfile1, replace) esample(esample22) ufmitest: streg   ///,
SSA_dum MENA_dum ASIPAC_dum CCE_dum if sample==1 & id != 119, dist(exp) vce(cluster id) time

mi estimate, hr
mi estimate, vartable dftable
how_many_imputations

mi test SSA_dum MENA_dum ASIPAC_dum CCE_dum, ufmitest



*base
mi estimate, saving(estfile1, replace) esample(esample42) ufmitest: streg   ///,
SSA_dum MENA_dum ASIPAC_dum CCE_dum tds_pct_gni urb_pop_pct lowmidinc_dum ///,
lowinc_dum log_elect polity prop_rep mix_other femschool_log year_from_suff ///,
femleg_log hr_log non29res_cedaw_rat wing_log reg_diff_dvprot log_gdppc ///,
if id != 119, dist(exp) vce(cluster id) time

mi estimate, hr
mi estimate, vartable dftable
how_many_imputations


mi test SSA_dum MENA_dum ASIPAC_dum CCE_dum, ufmitest

mi test lowmidinc_dum lowinc_dum, ufmitest

mi test prop_rep mix_other, ufmitest




*add cedawXwingos
mi estimate, saving(estfile1, replace) esample(esample1002) ufmitest: streg   ///,
SSA_dum MENA_dum ASIPAC_dum CCE_dum tds_pct_gni urb_pop_pct lowmidinc_dum ///,
lowinc_dum log_elect polity prop_rep mix_other femschool_log year_from_suff ///,
femleg_log hr_log non29res_cedaw_rat wing_log reg_diff_dvprot log_gdppc cedawXwingos ///,
if id != 119, dist(e) vce(cluster id) time

mi estimate, hr
mi estimate, vartable dftable
how_many_imputations


mi test SSA_dum MENA_dum ASIPAC_dum CCE_dum, ufmitest

mi test lowmidinc_dum lowinc_dum, ufmitest

mi test prop_rep mix_other, ufmitest


summarize wing_log if sample==1 & _st==1, d

*MICE margins 
mimrgns using estfile1, esample(esample1002) at( wing_log=(-2.5(.5)1.5) ///,
non29res_cedaw_rat=(0 1)) vsquish cmdmargins eform


collin tds_pct_gni urb_pop_pct log_elect polity femschool_log year_from_suff ///,
femleg_log hr_log wing_log reg_diff_dvprot log_gdppc if sample==1 & _st==1


clear






































































































***********************************************************************************

***********************************************************************************

***********************************************************************************

***********************************************************************************

***********************************************************************************

***********************************************************************************



























































































































******************************** CRIMINALIZATIONS  ****************************
******************************** EARLY PERIOD *********************************

use "[path_to_.dta_file_here.dta]"

******************** variable set up and creation ********************
sort id year

*recoding those handful of states that started as low/mid income then 
*moved to high inc over the course of the study (mostly post-Soviet)
recode lend_grp (1=1) (2=2) (3 4=3) (.=.)
tab lend_grp, gen(g)
rename g1 lowinc_dum
rename g2 lowmidinc_dum 
rename g3 upmid_highinc_dum

*making Beijing conference/attendance indicator for imputation model
tab og_beij, gen(g)
rename g1 pre_beij
rename g2 beij_norep
rename g3 beij_lt10
rename g4 beij_10om

gen igo_log = log(igo_imp)
gen ingo_log = log(ingo_imp)
gen gdppc_2018 = gdp_2018doll/pop_tot
gen log_pop = log(pop_tot)
gen log_gdppc = log(gdppc_2018)


*making early period adopter flag
gen s1 = dvcr_yr
recode s1 (1990/2003 0 = 1) (2004/2015 = 0) 


***/// Centering variables
sum tds_pct_gni if s1==1 & year < 2004, meanonly
gen tds_pct_gnic = tds_pct_gni-r(mean)
sum tds_pct_gnic if s1==1 & year < 2004
drop tds_pct_gni
rename tds_pct_gnic tds_pct_gni

sum urb_pop_pct if s1==1 & year < 2004, meanonly
gen urb_pop_pctc = urb_pop_pct-r(mean)
sum urb_pop_pctc if s1==1 & year < 2004
drop urb_pop_pct
rename urb_pop_pctc urb_pop_pct

sum polity if s1==1 & year < 2004, meanonly
gen polityc = polity-r(mean)
sum polityc if s1==1 & year < 2004
drop polity
rename polityc polity

sum year_from_suff if s1==1 & year < 2004, meanonly
gen year_from_suffc = year_from_suff-r(mean)
sum year_from_suffc if s1==1 & year < 2004
drop year_from_suff
rename year_from_suffc year_from_suff

sum reg_diff_dvcr if s1==1 & year < 2004, meanonly
gen reg_diff_dvcrc = reg_diff_dvcr-r(mean)
sum reg_diff_dvcrc if s1==1 & year < 2004
drop reg_diff_dvcr
rename reg_diff_dvcrc reg_diff_dvcr

sum log_elect if s1==1 & year < 2004, meanonly
gen log_electc = log_elect-r(mean)
sum log_electc if s1==1 & year < 2004
drop log_elect
rename log_electc log_elect

sum femschool_log if s1==1 & year < 2004, meanonly
gen femschool_logc = femschool_log-r(mean)
sum femschool_logc if s1==1 & year < 2004
drop femschool_log
rename femschool_logc femschool_log

sum hr_log if s1==1 & year < 2004, meanonly
gen hr_logc = hr_log-r(mean)
sum hr_logc if s1==1 & year < 2004
drop hr_log
rename hr_logc hr_log

sum wing_log if s1==1 & year < 2004, meanonly
gen wing_logc = wing_log-r(mean)
sum wing_logc if s1==1 & year < 2004
drop wing_log
rename wing_logc wing_log

sum femleg_log if s1==1 & year < 2004, meanonly
gen femleg_logc = femleg_log-r(mean)
sum femleg_logc if s1==1 & year < 2004
drop femleg_log
rename femleg_logc femleg_log

sum log_gdppc if s1==1 & year < 2004, meanonly
gen log_gdppcc = log_gdppc-r(mean)
sum log_gdppcc if s1==1 & year < 2004
drop log_gdppc
rename log_gdppcc log_gdppc


*generating interactions for use in models and imputation model
gen lowmidXdiff = lowmidinc_dum*reg_diff_dvcr
gen lowmidXwingos = lowmidinc_dum*wing_log
gen lowmidXfemleg = lowmidinc_dum*femleg_log
gen lowmidXcedaw = lowmidinc_dum*non29res_cedaw_rat

gen lowincXwingos = lowinc_dum*wing_log
gen lowincXfemleg = lowinc_dum*femleg_log
gen lowincXdiff = lowinc_dum*reg_diff_dvcr
gen lowincXcedaw = lowinc_dum*non29res_cedaw_rat

gen diffXwingos = reg_diff_dvcr*wing_log
gen cedawXwingos = non29res_cedaw_rat*wing_log


*******/////// Imputation procedure for dvcrim_EP

//** set mi style
mi set flong


//** declare variables for imputation
mi register imputed tds_pct_gni wing_log femleg_log lowincXfemleg lowmidXfemleg  ///,
femschool_log wingos lowincXwingos lowmidXwingos femschool_sec_gross igo_log ingo_log ///,
gdppc_2018 gdp_2018doll log_gdppc log_pop gdppc_2010 diffXwingos ///,
cedawXwingos 


***/// Use ICE imputation dvcrim_EP

mi impute chained (pmm, knn(6)) tds_pct_gni wing_log femschool_sec_gross ///,
femschool_log lowincXwingos lowmidXwingos wingos igo_log ingo_log ///
femleg_log lowincXfemleg lowmidXfemleg gdp_2018doll log_gdppc log_pop diffXwingos ///,
cedawXwingos gdppc_2018 gdppc_2010 ///,
 = dvcr SSA_dum MENA_dum ASIPAC_dum CCE_dum urb_pop_pct i.lowinc_dum pop_tot ///,
i.lowmidinc_dum left_part log_elect polity prop_rep mix_other dvcr_anyn ///,
year_from_suff  hr_log non29res_cedaw_rat ///,
post_beij demo_trans mort_u5 reg_diff_dvcr beij_norep ///,
lowincXcedaw lowmidXcedaw lowincXdiff lowmidXdiff ///,
beij_lt10 beij_10om pop_mil pop_0to14_pct fert_bpw i.id ///,
i.year if exist_flag==1 & year<2004, rseed(15132086) ///,
burnin(25) add(100) force aug dots



* set sample
gen sample = 0
replace sample =1 if ///,
SSA_dum !=. & MENA_dum !=. & ASIPAC_dum !=. & CCE_dum !=. & tds_pct_gni !=. & ///,
urb_pop_pct !=. & lowmidinc_dum !=. & lowinc_dum !=. & log_elect !=. & polity ///,
!=. & prop_rep !=. & mix_other !=. & femschool_log !=. & year_from_suff !=. & ///,
femleg_log !=. & hr_log !=. & non29res_cedaw_rat !=. & wing_log !=. & ///, 
reg_diff_dvcr !=. & log_gdppc !=.


*mi stset data and check impute stats
mi stset end if exist_flag==1 & s1==1 & year < 2004, failure(dvcr==1) ///, 
time0(start) id(id) exit(dvcr==1)
mi describe


******************** MODELS ********************


*region only
mi estimate, saving(estfile1, replace) esample(esample2) ufmitest: streg   ///,
SSA_dum MENA_dum ASIPAC_dum CCE_dum if sample==1 & id != 119, dist(e) vce(cluster id) time

mi estimate, hr
mi estimate, vartable dftable
how_many_imputations

mi test SSA_dum MENA_dum ASIPAC_dum CCE_dum, ufmitest



** base
mi estimate, saving(estfile1, replace) esample(esample42) ufmitest: streg   ///,
SSA_dum MENA_dum ASIPAC_dum CCE_dum tds_pct_gni urb_pop_pct lowmidinc_dum ///,
lowinc_dum log_elect polity prop_rep mix_other femschool_log year_from_suff ///,
femleg_log hr_log non29res_cedaw_rat wing_log reg_diff_dvcr log_gdppc ///,
if id != 119, dist(e) vce(cluster id) time

mi estimate, hr
mi estimate, vartable dftable
how_many_imputations


mi test SSA_dum MENA_dum ASIPAC_dum CCE_dum, ufmitest

mi test lowmidinc_dum lowinc_dum, ufmitest

mi test prop_rep mix_other, ufmitest




*base + incXcedaw
mi estimate, saving(estfile1, replace) esample(esample100) ufmitest: streg   ///,
SSA_dum MENA_dum ASIPAC_dum CCE_dum tds_pct_gni urb_pop_pct lowmidinc_dum ///,
lowinc_dum log_elect polity prop_rep mix_other femschool_log year_from_suff log_gdppc ///,
femleg_log hr_log non29res_cedaw_rat lowincXcedaw lowmidXcedaw ///,
reg_diff_dvcr wing_log if id != 119, dist(e) vce(cluster id) time

mi estimate, hr
mi estimate, vartable dftable
how_many_imputations


mi test SSA_dum MENA_dum ASIPAC_dum CCE_dum, ufmitest

mi test lowmidinc_dum lowinc_dum, ufmitest

mi test prop_rep mix_other, ufmitest

mi test lowincXcedaw lowmidXcedaw, ufmitest


*MICE margins 
mimrgns using estfile1, esample(esample100) at(non29res_cedaw_rat=(0 1) ///,
lowmidinc_dum=(0 1) lowinc_dum=(0 1)) vsquish cmdmargins eform


collin tds_pct_gni urb_pop_pct log_elect polity femschool_log year_from_suff ///,
femleg_log hr_log wing_log reg_diff_dvcr log_gdppc if sample==1 & _st==1


clear





























































































******************************** CRIMINALIZATIONS  ****************************
******************************** FULL PERIOD **********************************

use "[path_to_.dta_file_here.dta]"

******************** variable set up and creation ********************
sort id year

*recoding those handful of states that started as low/mid income then 
*moved to high inc over the course of the study (mostly post-Soviet)
recode lend_grp (1=1) (2=2) (3 4=3) (.=.)
tab lend_grp, gen(g)
rename g1 lowinc_dum
rename g2 lowmidinc_dum 
rename g3 upmid_highinc_dum

*making Beijing conference/attendance indicator for imputation model
tab og_beij, gen(g)
rename g1 pre_beij
rename g2 beij_norep
rename g3 beij_lt10
rename g4 beij_10om

gen igo_log = log(igo_imp)
gen ingo_log = log(ingo_imp)
gen gdppc_2018 = gdp_2018doll/pop_tot
gen log_pop = log(pop_tot)
gen log_gdppc = log(gdppc_2018)



***/// Centering variables
sum tds_pct_gni, meanonly
gen tds_pct_gnic = tds_pct_gni-r(mean)
sum tds_pct_gnic
drop tds_pct_gni
rename tds_pct_gnic tds_pct_gni

sum urb_pop_pct, meanonly
gen urb_pop_pctc = urb_pop_pct-r(mean)
sum urb_pop_pctc 
drop urb_pop_pct
rename urb_pop_pctc urb_pop_pct

sum polity, meanonly
gen polityc = polity-r(mean)
sum polityc
drop polity
rename polityc polity

sum year_from_suff, meanonly
gen year_from_suffc = year_from_suff-r(mean)
sum year_from_suffc
drop year_from_suff
rename year_from_suffc year_from_suff

sum reg_diff_dvcr, meanonly
gen reg_diff_dvcrc = reg_diff_dvcr-r(mean)
sum reg_diff_dvcrc
drop reg_diff_dvcr
rename reg_diff_dvcrc reg_diff_dvcr

sum log_elect, meanonly
gen log_electc = log_elect-r(mean)
sum log_electc
drop log_elect
rename log_electc log_elect

sum femschool_log, meanonly
gen femschool_logc = femschool_log-r(mean)
sum femschool_logc
drop femschool_log
rename femschool_logc femschool_log

sum hr_log, meanonly
gen hr_logc = hr_log-r(mean)
sum hr_logc
drop hr_log
rename hr_logc hr_log

sum wing_log, meanonly
gen wing_logc = wing_log-r(mean)
sum wing_logc
drop wing_log
rename wing_logc wing_log

sum femleg_log, meanonly
gen femleg_logc = femleg_log-r(mean)
sum femleg_logc
drop femleg_log
rename femleg_logc femleg_log

sum log_gdppc, meanonly
gen log_gdppcc = log_gdppc-r(mean)
sum log_gdppcc
drop log_gdppc
rename log_gdppcc log_gdppc


*generating interactions for use in models and imputation model
gen lowmidXdiff = lowmidinc_dum*reg_diff_dvcr
gen lowmidXwingos = lowmidinc_dum*wing_log
gen lowmidXfemleg = lowmidinc_dum*femleg_log
gen lowmidXcedaw = lowmidinc_dum*non29res_cedaw_rat

gen lowincXwingos = lowinc_dum*wing_log
gen lowincXfemleg = lowinc_dum*femleg_log
gen lowincXdiff = lowinc_dum*reg_diff_dvcr
gen lowincXcedaw = lowinc_dum*non29res_cedaw_rat

gen diffXwingos = reg_diff_dvcr*wing_log
gen cedawXwingos = non29res_cedaw_rat*wing_log


*******/////// Imputation procedure for dvcrim_FP

//** set mi style
mi set flong


//** declare variables for imputation
mi register imputed tds_pct_gni wing_log femleg_log lowincXfemleg lowmidXfemleg  ///,
femschool_log wingos lowincXwingos lowmidXwingos femschool_sec_gross igo_log ingo_log ///,
gdppc_2018 gdp_2018doll log_gdppc log_pop gdppc_2010 diffXwingos ///,
cedawXwingos


***/// Use ICE imputation dvcrim_FP

mi impute chained (pmm, knn(8)) tds_pct_gni wing_log femschool_sec_gross ///,
femschool_log lowmidXwingos lowincXwingos wingos igo_log ingo_log ///
femleg_log lowincXfemleg lowmidXfemleg gdp_2018doll log_gdppc log_pop diffXwingos ///,
cedawXwingos gdppc_2018 gdppc_2010 ///,
 = dvcr SSA_dum MENA_dum ASIPAC_dum CCE_dum urb_pop_pct lowinc_dum pop_tot ///,
lowmidinc_dum left_part log_elect polity prop_rep mix_other dvcr_anyn ///,
year_from_suff  hr_log non29res_cedaw_rat ///,
post_beij demo_trans mort_u5 reg_diff_dvcr beij_norep ///,
lowincXcedaw lowmidXcedaw lowincXdiff lowmidXdiff ///,
beij_lt10 beij_10om pop_mil pop_0to14_pct fert_bpw i.id ///,
i.year if exist_flag==1, rseed(15132086) ///,
burnin(25) add(100) force aug dots


* set sample
gen sample = 0
replace sample =1 if ///,
SSA_dum !=. & MENA_dum !=. & ASIPAC_dum !=. & CCE_dum !=. & tds_pct_gni !=. & ///,
urb_pop_pct !=. & lowmidinc_dum !=. & lowinc_dum !=. & log_elect !=. & polity ///,
!=. & prop_rep !=. & mix_other !=. & femschool_log !=. & year_from_suff !=. & ///,
femleg_log !=. & hr_log !=. & non29res_cedaw_rat !=. & wing_log !=. & ///, 
reg_diff_dvcr !=. & log_gdppc !=.

*mi stset data and check impute stats
mi stset end if exist_flag==1, failure(dvcr==1) time0(start) id(id) exit(dvcr==1)
mi describe


******************** MODELS ********************


**region only
mi estimate, saving(estfile1, replace) esample(esample4) ufmitest: streg   ///,
SSA_dum MENA_dum ASIPAC_dum CCE_dum if sample==1 & id != 119, dist(e) vce(cluster id) time

mi estimate, hr
mi estimate, vartable dftable
how_many_imputations

mi test SSA_dum MENA_dum ASIPAC_dum CCE_dum, ufmitest



** base
mi estimate, saving(estfile1, replace) esample(esample42) ufmitest: streg   ///,
SSA_dum MENA_dum ASIPAC_dum CCE_dum tds_pct_gni urb_pop_pct lowmidinc_dum ///,
lowinc_dum log_elect polity prop_rep mix_other femschool_log year_from_suff ///,
femleg_log hr_log non29res_cedaw_rat wing_log reg_diff_dvcr log_gdppc ///,
if id != 119, dist(e) vce(cluster id) time

mi estimate, hr
mi estimate, vartable dftable
how_many_imputations


mi test SSA_dum MENA_dum ASIPAC_dum CCE_dum, ufmitest

mi test lowmidinc_dum lowinc_dum, ufmitest

mi test prop_rep mix_other, ufmitest



** base + incXcedaw
mi estimate, saving(estfile1, replace) esample(esample100) ufmitest: streg   ///,
SSA_dum MENA_dum ASIPAC_dum CCE_dum tds_pct_gni urb_pop_pct lowmidinc_dum ///,
lowinc_dum log_elect polity prop_rep mix_other femschool_log year_from_suff log_gdppc ///,
femleg_log hr_log non29res_cedaw_rat lowincXcedaw lowmidXcedaw ///,
reg_diff_dvcr wing_log if id != 119, dist(e) vce(cluster id) time

mi estimate, hr
mi estimate, vartable dftable
how_many_imputations



mi test SSA_dum MENA_dum ASIPAC_dum CCE_dum, ufmitest

mi test lowmidinc_dum lowinc_dum, ufmitest

mi test prop_rep mix_other, ufmitest

mi test lowincXcedaw lowmidXcedaw, ufmitest


*MICE margins 
mimrgns using estfile1, esample(esample100) at(non29res_cedaw_rat=(0 1) ///,
lowmidinc_dum=(0 1) lowinc_dum=(0 1)) vsquish cmdmargins eform


collin tds_pct_gni urb_pop_pct log_elect polity femschool_log year_from_suff ///,
femleg_log hr_log wing_log reg_diff_dvcr log_gdppc if sample==1 & _st==1


clear



